package io.renren.modules.sq.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.sq.entity.SqSystemEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sq.dao.SqSystemEditionDao;
import io.renren.modules.sq.entity.SqSystemEditionEntity;
import io.renren.modules.sq.service.SqSystemEditionService;
import org.springframework.util.StringUtils;


@Service("sqSystemEditionService")
public class SqSystemEditionServiceImpl extends ServiceImpl<SqSystemEditionDao, SqSystemEditionEntity> implements SqSystemEditionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SqSystemEditionEntity> page = this.page(
                new Query<SqSystemEditionEntity>().getPage(params),
                new QueryWrapper<SqSystemEditionEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Page<SqSystemEditionEntity> getSysEditionList(Map<String, Object> params) {
        Page<SqSystemEditionEntity> page = new PageUtils<SqSystemEditionEntity>().getPageByParams(params);
        QueryWrapper<SqSystemEditionEntity> queryWrapper = new QueryWrapper<>();
        String systemId = (String) params.get("systemId"); // 系统ID
        String systemEdition = (String) params.get("systemEdition"); // 系统版本
        String systemDescription = (String) params.get("systemDescription"); // 描述
        if(StringUtils.hasText(systemId)) {
            queryWrapper.like("system_id", Long.parseLong(systemId));
        }
        if(StringUtils.hasText(systemEdition)) {
            queryWrapper.like("system_edition", systemEdition);
        }
        if(StringUtils.hasText(systemDescription)) {
            queryWrapper.like("system_description", systemDescription);
        }
        baseMapper.selectPage(page, queryWrapper);
        return page;
    }

}
